from mainApp.models import *
from typing import List


def get_user_permission(username: str) -> List[str]:
    """
    查询用户所有权限
    :param username: 网站用户名
    :return:
    """
    result: List[str] = []
    roles = UserRole.objects.filter(username=username)
    result += [x.permission for x in RolePermission.objects.filter(role__in=roles)]

    groups = UserGroup.objects.filter(username=username)
    result += [x.permission for x in GroupPermission.objects.filter(group__in=groups)]
    return result


def sql_parser(sql: str) -> str:
    pass
